﻿using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom;
using System.Collections.ObjectModel;
using CodeDomHelper.Types;

namespace devtm.Templates
{

    public class TemplateModelObservableCollection : ITemplateModel
    {

        public string Name { get { return "ObservableCollection"; } }
        public string Parameter { get; set; }
        public bool IsEnumerable { get { return true; } }
        public string DescriptionParameter { get { return string.Empty; } }
        public bool NeedParameter { get { return false; } }
        public string MapperName { get; set; }

        public CodeExpression CreateObject()
        {
            var r = Type.Translate(typeof(ObservableCollection<>));
            return new CodeObjectCreateExpression(r.ToString());
        }


        public CodeExpression InsertItem(CodeVariableReferenceExpression item, CodeVariableReferenceExpression target)
        {

            var r = Type.Translate(typeof(ObservableCollection<>));

            return

                new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(
                        new CodeCastExpression(r.AssemblyQualifiedName, target), "Add"), item);
        }


        public TypeExpression Type { get; set; }


    }

}
